/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JCatalogKeyBoardDialog.java
 *
 * Created on 2009-9-12, 13:19:23
 */

package com.openbravo.pos.sales;

import cn.ekuma.epos.catalog.JCatalog;
import cn.ekuma.epos.datalogic.I_DataLogicSales;
import cn.ekuma.swing.dialog.AbstractKeyBoardJDialog;

import com.openbravo.bean.sales.ShoppingCart;
import com.openbravo.data.basic.BasicException;
import com.openbravo.pos.panels.JPanelButtons;
import com.openbravo.pos.util.ThumbNailBuilder;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
/**
 *
 * @author Administrator
 */
public class JCatalogKeyBoardDialog extends AbstractKeyBoardJDialog implements ActionListener{


    private boolean isSignSelected;

    /** Creates new form JCatalogKeyBoardDialog 
     * @wbp.parser.constructor*/
    public JCatalogKeyBoardDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
       
    }

     /** Creates new form JTicketsBagSharedList */
    private  JCatalogKeyBoardDialog(java.awt.Dialog parent, boolean modal) {
        super(parent, modal);
    }

    
    private ThumbNailBuilder tnbbutton;
    private boolean isOK;
    JCatalog jcatalog;
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel2 = new javax.swing.JPanel();
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jPanel2.setLayout(new java.awt.BorderLayout());
        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    }// </editor-fold>//GEN-END:initComponents
   

    public static JCatalogKeyBoardDialog newJDialog(Component ticketSell,I_DataLogicSales dlSales,JPanelButtons m_jbtnconfig,boolean isSign) throws BasicException {
        Window window = getWindow(ticketSell);
        JCatalogKeyBoardDialog mydialog;
        if (window instanceof Frame) {
            mydialog = new JCatalogKeyBoardDialog((Frame) window, true);
        } else {
            mydialog = new JCatalogKeyBoardDialog((Dialog) window, true);
        }
        mydialog.init(dlSales,m_jbtnconfig);
        return mydialog;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel2;

    // End of variables declaration//GEN-END:variables

    
    private void init(I_DataLogicSales dlSales,JPanelButtons m_jbtnconfig) throws BasicException{
        initComponents();
        jcatalog=new JCatalog(dlSales,
                "true".equals(m_jbtnconfig.getProperty("pricevisible")),
                "true".equals(m_jbtnconfig.getProperty("taxesincluded")),
                 Integer.parseInt(m_jbtnconfig.getProperty("img-width", "64")),
                 Integer.parseInt(m_jbtnconfig.getProperty("img-height", "54")));
         jcatalog.loadCatalog();
         jcatalog.addActionListener(this);
         jPanel2.add(jcatalog, java.awt.BorderLayout.CENTER);
         setSizeFullOfScreen(this);
    }


    public static final Toolkit toolkit = Toolkit.getDefaultToolkit();
     /**
      * 将window全屏,对Window,Frame,Dialog,JWindow,JFrame,JDialog有效
      * @param window 全屏化的window
      * @see Window,Frame,Dialog,JWindow,JFrame,JDialog
      */
     public static void setSizeFullOfScreen(Window window) {
         Dimension screenSize = toolkit.getScreenSize();
         window.setBounds(0, 0, screenSize.width, screenSize.height-60);
     }

    @Override
    protected void enterKeyProc() {
         dispose();
    }

    @Override
    protected void escapeKeyProc() {
         dispose();
    }

    public boolean isOK() {
        return isOK;
    }

    public void reset() {
    	jcatalog.reset();
    }

	@Override
	protected void upKeyProc() {	
	}

	@Override
	protected void downKeyProc() {
	}
	
	public ShoppingCart getShoppingCart(){
		return jcatalog.getShoppingCart();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		enterKeyProc();
	}
}
